package com.software.loginregister.api;

import com.software.loginregister.entity.Result;
import com.software.loginregister.entity.SearchHistory;
import com.software.loginregister.entity.Works;
import com.software.loginregister.entity.vo.CookingStepVO;
import com.software.loginregister.entity.vo.IngredientDTO;
import com.software.loginregister.entity.vo.MyWorkDetailVO;
import com.software.loginregister.entity.vo.WorksDTO;

import java.util.List;
import java.util.Map;

import retrofit2.Call;
import retrofit2.http.DELETE;
import retrofit2.http.GET;
import retrofit2.http.POST;
import retrofit2.http.Part;
import retrofit2.http.Path;
import retrofit2.http.Query;
import retrofit2.http.Body;
import retrofit2.http.Multipart;
import okhttp3.MultipartBody;

public interface WorksApi {
    @GET("works/{worksId}/steps")
    Call<com.software.loginregister.entity.Result<List<CookingStepVO>>> getSteps(@Path("worksId") Long worksId);

    @GET("ingredients/recipe/{workId}")
    Call<com.software.loginregister.entity.Result<List<IngredientDTO>>> getRecipeIngredients(@Path("workId") Integer workId);


    @POST("works/toggleLike")
    Call<com.software.loginregister.entity.Result<Map<String, Object>>> toggleLike(@Query("worksId") long worksId, @Query("userId") long userId);

    @GET("works/user/{userId}")
    Call<com.software.loginregister.entity.Result<List<MyWorkDetailVO>>> getUserWorks(@Path("userId") Integer userId);


    @GET("/works/search")
    Call<com.software.loginregister.entity.Result<List<com.software.loginregister.entity.vo.WorksSearchListVo>>> searchWorks(
            @Query("keyword") String keyword,
            @Query("difficulty") String difficulty,
            @Query("ingredients") String ingredients,
            @Query("userId") Long userId,
            @Query("sortBy") String sortBy,
            @Query("page") Integer page,
            @Query("pageSize") Integer pageSize
    );

    // 获取搜索历史
    @GET("/works/search/history")
    Call<Result<List<SearchHistory>>> getSearchHistory(
            @Query("userId") Long userId,
            @Query("limit") int limit
    );

    // 清除搜索历史
    @DELETE("/works/clear/history")
    Call<Result<Void>> clearSearchHistory(
            @Query("userId") Long userId
    );

    @Multipart
    @POST("/works/publish-new")
    Call<Result<Works>> publishWork(
            @Part MultipartBody.Part mainPhoto,
            @Part List<MultipartBody.Part> stepPhotos,  // 确保参数名匹配
            @Part("publishDTO") okhttp3.RequestBody publishDTO
    );

    @Multipart
    @POST("/works/save-draft")
    Call<Result<Works>> saveDraft(
            @Part MultipartBody.Part mainPhoto,
            @Part List<MultipartBody.Part> stepPhotos,
            @Part("publishDTO") okhttp3.RequestBody publishDTO
    );

    @POST("/works/save-draft-without-photos")
    Call<Result<Works>> saveDraftWithoutPhotos(@Body okhttp3.RequestBody publishDTO);

    @GET("/works/drafts")
    Call<Result<List<Works>>> getDrafts(@Query("userId") Integer userId);

    @GET("works/draft/{draftId}")
    Call<Result<Works>> getDraftDetail(
            @Path("draftId") Integer draftId,
            @Query("userId") Integer userId
    );

    @GET("/api/recommendation/works")
    Call<Result<List<WorksDTO>>> getRecommendedWorks(
            @Query("userId") Long userId,
            @Query("limit") int limit
    );

    @POST("works/increaseViewCount/{worksId}")
    Call<Result<Void>> increaseViewCount(@Path("worksId") int worksId);

    @POST("works/record-browsing-history")
    Call<Result<Void>> recordBrowsingHistory(
            @Query("userId") Long userId,
            @Query("worksId") Integer worksId
    );

    @GET("works/{worksId}/likes")
    Call<Result<Map<String, Object>>> getLikes(@Path("worksId") Long worksId);
    @GET("works/ranking/hot")
    Call<Result<List<Map<String, Object>>>> getHotWorks();

}
